package com.wuxianedu.httpclient;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by TED on 2016/9/26.
 */
public class ImageLoader {


    public static void loader(final Listener load) {
        new Thread(new Runnable() {
            @Override
            public void run() {

                try {
                    HttpClient client = new DefaultHttpClient();
                    HttpGet get = new HttpGet(Contents.IMAGE_URL);
                    HttpResponse response = null;
                    response = client.execute(get);
                    HttpEntity entity = response.getEntity();
                    InputStream is = entity.getContent();
                    Bitmap bitmap = BitmapFactory.decodeStream(is);
                    load.method(bitmap);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }).start();
    }

    public interface Listener {
        void method(Bitmap bitmap);
    }

}
